home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / javax / swing / TransferHandler.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  6.0 KB  |  223 lines

  1. package javax.swing;
  2.  
  3. import java.awt.GraphicsEnvironment;
  4. import java.awt.datatransfer.Clipboard;
  5. import java.awt.datatransfer.ClipboardOwner;
  6. import java.awt.datatransfer.DataFlavor;
  7. import java.awt.datatransfer.Transferable;
  8. import java.awt.dnd.DropTargetListener;
  9. import java.awt.event.InputEvent;
  10. import java.awt.event.MouseEvent;
  11. import java.beans.BeanInfo;
  12. import java.beans.IntrospectionException;
  13. import java.beans.Introspector;
  14. import java.beans.PropertyDescriptor;
  15. import java.io.Serializable;
  16. import java.lang.reflect.Method;
  17. import sun.awt.AppContext;
  18. import sun.reflect.misc.MethodUtil;
  19.  
  20. public class TransferHandler implements Serializable {
  21.    public static final int NONE = 0;
  22.    public static final int COPY = 1;
  23.    public static final int MOVE = 2;
  24.    public static final int COPY_OR_MOVE = 3;
  25.    public static final int LINK = 1073741824;
  26.    private String propertyName;
  27.    private static SwingDragGestureRecognizer recognizer = null;
  28.    static final Action cutAction = new TransferAction("cut");
  29.    static final Action copyAction = new TransferAction("copy");
  30.    static final Action pasteAction = new TransferAction("paste");
  31.  
  32.    public static Action getCutAction() {
  33.       return cutAction;
  34.    }
  35.  
  36.    public static Action getCopyAction() {
  37.       return copyAction;
  38.    }
  39.  
  40.    public static Action getPasteAction() {
  41.       return pasteAction;
  42.    }
  43.  
  44.    public TransferHandler(String var1) {
  45.       this.propertyName = var1;
  46.    }
  47.  
  48.    protected TransferHandler() {
  49.       this((String)null);
  50.    }
  51.  
  52.    public void exportAsDrag(JComponent var1, InputEvent var2, int var3) {
  53.       int var4 = this.getSourceActions(var1);
  54.       if (!(var2 instanceof MouseEvent) || var3 != 1 && var3 != 2 && var3 != 1073741824 || (var4 & var3) == 0) {
  55.          var3 = 0;
  56.       }
  57.  
  58.       if (var3 != 0 && !GraphicsEnvironment.isHeadless()) {
  59.          if (recognizer == null) {
  60.             recognizer = new SwingDragGestureRecognizer(new DragHandler((1)null));
  61.          }
  62.  
  63.          recognizer.gestured(var1, (MouseEvent)var2, var4, var3);
  64.       } else {
  65.          this.exportDone(var1, (Transferable)null, 0);
  66.       }
  67.  
  68.    }
  69.  
  70.    public void exportToClipboard(JComponent var1, Clipboard var2, int var3) throws IllegalStateException {
  71.       if ((var3 == 1 || var3 == 2) && (this.getSourceActions(var1) & var3) != 0) {
  72.          Transferable var4 = this.createTransferable(var1);
  73.          if (var4 != null) {
  74.             try {
  75.                var2.setContents(var4, (ClipboardOwner)null);
  76.                this.exportDone(var1, var4, var3);
  77.                return;
  78.             } catch (IllegalStateException var6) {
  79.                this.exportDone(var1, var4, 0);
  80.                throw var6;
  81.             }
  82.          }
  83.       }
  84.  
  85.       this.exportDone(var1, (Transferable)null, 0);
  86.    }
  87.  
  88.    public boolean importData(TransferSupport var1) {
  89.       return var1.getComponent() instanceof JComponent ? this.importData((JComponent)var1.getComponent(), var1.getTransferable()) : false;
  90.    }
  91.  
  92.    public boolean importData(JComponent var1, Transferable var2) {
  93.       PropertyDescriptor var3 = this.getPropertyDescriptor(var1);
  94.       if (var3 != null) {
  95.          Method var4 = var3.getWriteMethod();
  96.          if (var4 == null) {
  97.             return false;
  98.          }
  99.  
  100.          Class[] var5 = var4.getParameterTypes();
  101.          if (var5.length != 1) {
  102.             return false;
  103.          }
  104.  
  105.          DataFlavor var6 = this.getPropertyDataFlavor(var5[0], var2.getTransferDataFlavors());
  106.          if (var6 != null) {
  107.             try {
  108.                Object var7 = var2.getTransferData(var6);
  109.                Object[] var8 = new Object[]{var7};
  110.                MethodUtil.invoke(var4, var1, var8);
  111.                return true;
  112.             } catch (Exception var9) {
  113.                System.err.println("Invocation failed");
  114.             }
  115.          }
  116.       }
  117.  
  118.       return false;
  119.    }
  120.  
  121.    public boolean canImport(TransferSupport var1) {
  122.       return var1.getComponent() instanceof JComponent ? this.canImport((JComponent)var1.getComponent(), var1.getDataFlavors()) : false;
  123.    }
  124.  
  125.    public boolean canImport(JComponent var1, DataFlavor[] var2) {
  126.       PropertyDescriptor var3 = this.getPropertyDescriptor(var1);
  127.       if (var3 != null) {
  128.          Method var4 = var3.getWriteMethod();
  129.          if (var4 == null) {
  130.             return false;
  131.          }
  132.  
  133.          Class[] var5 = var4.getParameterTypes();
  134.          if (var5.length != 1) {
  135.             return false;
  136.          }
  137.  
  138.          DataFlavor var6 = this.getPropertyDataFlavor(var5[0], var2);
  139.          if (var6 != null) {
  140.             return true;
  141.          }
  142.       }
  143.  
  144.       return false;
  145.    }
  146.  
  147.    public int getSourceActions(JComponent var1) {
  148.       PropertyDescriptor var2 = this.getPropertyDescriptor(var1);
  149.       return var2 != null ? 1 : 0;
  150.    }
  151.  
  152.    public Icon getVisualRepresentation(Transferable var1) {
  153.       return null;
  154.    }
  155.  
  156.    protected Transferable createTransferable(JComponent var1) {
  157.       PropertyDescriptor var2 = this.getPropertyDescriptor(var1);
  158.       return var2 != null ? new PropertyTransferable(var2, var1) : null;
  159.    }
  160.  
  161.    protected void exportDone(JComponent var1, Transferable var2, int var3) {
  162.    }
  163.  
  164.    private PropertyDescriptor getPropertyDescriptor(JComponent var1) {
  165.       if (this.propertyName == null) {
  166.          return null;
  167.       } else {
  168.          Class var2 = var1.getClass();
  169.  
  170.          BeanInfo var3;
  171.          try {
  172.             var3 = Introspector.getBeanInfo(var2);
  173.          } catch (IntrospectionException var8) {
  174.             return null;
  175.          }
  176.  
  177.          PropertyDescriptor[] var4 = var3.getPropertyDescriptors();
  178.  
  179.          for(int var5 = 0; var5 < var4.length; ++var5) {
  180.             if (this.propertyName.equals(var4[var5].getName())) {
  181.                Method var6 = var4[var5].getReadMethod();
  182.                if (var6 != null) {
  183.                   Class[] var7 = var6.getParameterTypes();
  184.                   if (var7 == null || var7.length == 0) {
  185.                      return var4[var5];
  186.                   }
  187.                }
  188.             }
  189.          }
  190.  
  191.          return null;
  192.       }
  193.    }
  194.  
  195.    private DataFlavor getPropertyDataFlavor(Class<?> var1, DataFlavor[] var2) {
  196.       for(int var3 = 0; var3 < var2.length; ++var3) {
  197.          DataFlavor var4 = var2[var3];
  198.          if ("application".equals(var4.getPrimaryType()) && "x-java-jvm-local-objectref".equals(var4.getSubType()) && var1.isAssignableFrom(var4.getRepresentationClass())) {
  199.             return var4;
  200.          }
  201.       }
  202.  
  203.       return null;
  204.    }
  205.  
  206.    private static DropTargetListener getDropTargetListener() {
  207.       synchronized(DropHandler.class) {
  208.          DropHandler var1 = (DropHandler)AppContext.getAppContext().get(DropHandler.class);
  209.          if (var1 == null) {
  210.             var1 = new DropHandler((1)null);
  211.             AppContext.getAppContext().put(DropHandler.class, var1);
  212.          }
  213.  
  214.          return var1;
  215.       }
  216.    }
  217.  
  218.    // $FF: synthetic method
  219.    static DropTargetListener access$200() {
  220.       return getDropTargetListener();
  221.    }
  222. }
  223.